import axios from "axios";
import { ElMessage } from "element-plus";
import {useRouter} from 'vue-router'
const development = import.meta.env['VITE_ENV']
console.log(development)
const http = axios.create({
  baseURL: '/api',
  timeout: 5000
})
const whiteAPIList = ['/user/captcha']
http.interceptors.request.use((config) => {
  // console.log(config)
  // // if(whiteAPIList.)
  // const token = localStorage.getItem('aaa')
  // if(!token) {
  //   const router = useRouter()
  //   router.push('/loin')
  // }
  // config.headers['Authorization'] = token
  return config
})
http.interceptors.response.use(
  (response) => {
    const res = response.data
    if(res.code===200) {
      return res.data
    } else {
      ElMessage.error('请求错误，请重试')
      return Promise.reject(res.msg);
    }
  }
)
export default http